{% extends 'base.html' %}
{% load mytags %}


{% block content %}
    {% include 'nav_cat_bar.html' %}
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-10">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>填写基本信息</h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                            <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                                <i class="fa fa-wrench"></i>
                            </a>
                            <a class="close-link">
                                <i class="fa fa-times"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <form method="post" id="userForm" class="form-horizontal" action="">
                            {% csrf_token %}
                            {% if error %}
                                <div class="alert alert-warning text-center">{{ error }}</div>
                            {% endif %}
                            {% if msg %}
                                <div class="alert alert-success text-center">{{ msg }}</div>
                            {% endif %}
                            <div class="form-group">
                                <label for="username" class="col-sm-2 control-label">用户名<span class="red-fonts">*</span></label>
                                <div class="col-sm-8">
                                    <input id="username" name="username" placeholder="Username" type="text" class="form-control" {% if error %}value="{{ username }}" {% endif %}>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label for="displayName" class="col-sm-2 control-label">姓名<span class="red-fonts">*</span></label>
                                <div class="col-sm-8">
                                    <input id="displayName" name="displayName" placeholder="中文姓名" type="text" class="form-control" {% if error %}value="{{ displayName }}" {% endif %} >
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label for="password" class="col-sm-2 control-label">密码<span class="red-fonts">*</span></label>
                                <div class="col-sm-8">
                                    <input id="password" name="password" placeholder="" type="password" class="form-control" >
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label for="email" class="col-sm-2 control-label">Email<span class="red-fonts">*</span></label>
                                <div class="col-sm-8">
                                    <input id="email" name="email" type="email" placeholder="username@jidongnet.com" class="form-control" {% if error %}value="{{ email }}" {% endif %}>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="department" class="col-sm-2 control-label">部门</label>
                                <div class="col-sm-3">
                                    <select id="department" name="department" size="6" class="form-control m-b" multiple="">
                                            {% for f,n in dep_list.items %}
                                                {% if forloop.first %}
                                                    <option value="{{ f }}" selected="true">{{ n }}</option>
                                                {% else %}
                                                    <option value="{{ f }}">{{ n }}</option>
                                                {% endif %}
                                            {% endfor %}
                                    </select>
                                </div>
                                <div class="col-sm-1">
                                    <div class="btn-group" style="margin-top: 50px;">
                                        <button type="button" class="btn btn-white" onclick="move('department', 'department_selected')"><i class="fa fa-chevron-right"></i></button>
                                        <button type="button" class="btn btn-white" onclick="move('department_selected', 'department')"><i class="fa fa-chevron-left"></i> </button>
                                    </div>
                                </div>
                                <div class="col-sm-3">
                                    <div>
                                        <select id="department_selected" name="department_selected" class="form-control m-b" size="6" multiple="">
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label for="group" class="col-sm-2 control-label">用户组</label>
                                <div class="col-sm-3">
                                    <select id="group" name="group" size="6" class="form-control m-b" multiple="">
                                            {% for f,n in grp_list.items %}
                                                {% if forloop.first %}
                                                    <option value="{{ f }}" selected="true">{{ n }}</option>
                                                {% else %}
                                                    <option value="{{ f }}">{{ n }}</option>
                                                {% endif %}
                                            {% endfor %}
                                    </select>
                                </div>
                                <div class="col-sm-1">
                                    <div class="btn-group" style="margin-top: 50px;">
                                        <button type="button" class="btn btn-white" onclick="move('group', 'group_selected')"><i class="fa fa-chevron-right"></i></button>
                                        <button type="button" class="btn btn-white" onclick="move('group_selected', 'group')"><i class="fa fa-chevron-left"></i> </button>
                                    </div>
                                </div>
                                <div class="col-sm-3">
                                    <div>
                                        <select id="group_selected" name="group_selected" class="form-control m-b" size="6" multiple="">
                                        </select>
                                    </div>
                                </div>
                            </div>

                            <div class="hr-line-dashed"></div>
                            <div class="form-group"><label class="col-sm-2 control-label">其它</label>
                                <div class="col-sm-2">
                                    <div class="checkbox i-checks">
                                        <label><input id="disabled" type="checkbox" value="0" name="extra" >禁用 </label>
                                    </div>
                                </div>
                                <div class="col-sm-2">
                                    <div class="checkbox i-checks">
                                        <label><input id="send_mail_need" type="checkbox" value="1" name="extra" checked=true>发送邮件 </label>
                                    </div>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-2">
                                    <button class="btn btn-white" type="reset">取消</button>
                                    <button id="submit_button" class="btn btn-primary" type="submit">确认保存</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
{% endblock %}
{% block self_footer_js %}

<script>
$('#userForm').validator({
    timely: 2,
    theme: "yellow_right_effect",
    rules: {
        check_username: [/^[\w.]{3,20}$/, '大小写字母数字和下划线小数点'],
        check_displayName: [/[\u4E00-\u9FA5\uF900-\uFA2D]/, '检查中文.'],
        check_email:   [/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/,'邮箱格式不正确'],
        type_m: function(element){
                    return  $("#M").is(":checked");
            },
    },
    fields: {
        "username": {
            rule: "required;check_username",
            tip: "输入用户名",
            ok: "",
            msg: {required: "必须填写!"}
        },
        "password": {
            rule: "length[6~50]",
            tip: "输入密码,不填写则自动随机生成.",
            ok: "",
            msg: {required: "必须填写!"}
        },
        "displayName": {
            rule: "required;check_displayName",
            tip: "姓名",
            ok: "",
            msg: {required: "必须填写",check_displayName: "必须为中文名"}
        },
        "email": {
            rule: "required;check_email",
            tip: "Email",
            ok: "",
            msg: {required: "必须填写",check_email: "邮箱格式不正确"}
        }
    },
    valid: function(form) {
        form.submit();
    }
});

</script>
{% endblock %}
